require("../../utils/util.js");

var t = require("date.js"), a = require("getCNDate.js"), e = (getApp(), new Date());

Page({
    data: {
        monthNum: e.getMonth() + 1,
        yearNum: e.getFullYear(),
        MonthDayArray: [],
        toDate: e.getDate(),
        toMonth: e.getMonth() + 1,
        toYear: e.getFullYear(),
        fromToday: "今天",
        nongliDetail: a(e.getFullYear(), e.getMonth() + 1, e.getDate())
    },
    onShow: function() {
        this.calcMonthDayArray();
    },
    dateClick: function(e) {
        var o = e.currentTarget.id, n = this.data.MonthDayArray, r = this.data;
        if ("" != o) {
            for (h = 0; h < n.length; h++) for (m = 0; m < n[h].length; m++) "string" != typeof n[h][m] && n[h][m].num == o && (n[h][m].isShowDayInfo = !n[h][m].isShowDayInfo);
            for (var h = 0; h < n.length; h++) for (var m = 0; m < n[h].length; m++) "string" != typeof n[h][m] && n[h][m].num != o && (n[h][m].isShowDayInfo = !1);
            this.setData({
                MonthDayArray: n,
                toYear: r.yearNum,
                toMonth: r.monthNum,
                toDate: o,
                fromToday: t.getFromTodayDays(o, r.monthNum - 1, r.yearNum),
                nongliDetail: a(r.yearNum, r.monthNum, o)
            });
        }
    },
    monthTouch: function(t) {
        var a = t.target.offsetLeft, e = t.changedTouches[0].clientX;
        a - e > 60 ? this.nextMonth_Fn() : a - e < -60 && this.lastMonth_Fn();
    },
    nextMonth_Fn: function() {
        var t = this.data.monthNum, a = this.data.yearNum;
        12 == t ? this.setData({
            monthNum: 1,
            yearNum: a + 1
        }) : this.setData({
            monthNum: t + 1
        }), this.calcMonthDayArray();
    },
    lastMonth_Fn: function() {
        var t = this.data.monthNum, a = this.data.yearNum;
        1 == t ? this.setData({
            monthNum: 12,
            yearNum: a - 1
        }) : this.setData({
            monthNum: t - 1
        }), this.calcMonthDayArray();
    },
    calcMonthDayArray: function() {
        var o = this.data, n = t.paintCalendarArray(o.monthNum, o.yearNum), r = o.monthNum != e.getMonth() + 1 || o.yearNum != e.getFullYear();
        if (r) for (var h = 0; h < n[0].length; h++) 1 == n[0][h].num && (n[0][h].isShowDayInfo = !0);
        this.setData({
            MonthDayArray: n,
            toYear: r ? this.data.yearNum : e.getFullYear(),
            toMonth: r ? this.data.monthNum : e.getMonth() + 1,
            toDate: r ? 1 : e.getDate(),
            fromToday: r ? t.getFromTodayDays(1, o.monthNum - 1, o.yearNum) : "今天",
            nongliDetail: r ? a(o.yearNum, o.monthNum, 1) : a(e.getFullYear(), e.getMonth() + 1, e.getDate())
        });
    }
});